/* $Header: valve.h,v 2.3 01/10/05 10:42:46 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  valve.h                                         */
/* ==================                                                  */
/*                                                                     */
/* Author:  Lesley Freed                                               */
/*                                                                     */
/* COMMENT:  Defines the data structures, constants, and macros used   */
/*           for the user controllable valves ( valves 1-8 ).          */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef VALVE_H
#define VALVE_H

/*****************************/
/*   IFDEFS                  */
/*****************************/


/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

#define MIN_LOOP_VOLUME  1         /* 1 ul (.001 ml) */
#define DEFAULT_LOOP_VOL 1000      /* 1 ml           */
#define MAX_LOOP_VOLUME  10000     /* 10 ml          */

#define MIN_INJECT_TIME  1         /* .01 minutes     */
#define DEFAULT_INJ_TIME 50*600    /* .5 minutes, internal fmt */
#define MAX_INJECT_TIME  99999     /* 999.99 minutes  */

#define MIN_LOAD_TIME     1        /*.01 minutes      */
#define DEFAULT_LOAD_TIME 50*600   /* .5 minutes, internal fmt */
#define MAX_LOAD_TIME     99999    /* 999.99 minutes  */

#define MIN_STREAM_NO   1
#define MAX_STREAM_NO   32
#define INVALID_BCD     100

#define MIN_SWITCH_TIME 10         /* 1  sec      */
#define MAX_SWITCH_TIME 1000       /* 100 sec     */
#define DEFAULT_SWITCH_TIME 10*5   /* 1  sec, internal format */


/*****************************/
/*   MACROS                  */
/*****************************/


/*****************************/
/*   TYPEDEFS                */
/*****************************/

typedef enum {IN_CONTROL = 0,
              ON_TIME    = 1,
              OFF_TIME   = 2,
              SCREWUP    = 3
             } STREAM_STATE;


typedef enum {GSV_IDLE   = 0,
              GSV_FILL   = 1,
              GSV_INJECT = 2
             } GSV_STATE;


/****************************/
/*   EXTERNAL VARIABLES     */
/****************************/

extern STREAM_STATE Stream_State;
extern GSV_STATE    Gsv1_State;
extern GSV_STATE    Gsv2_State;
extern U_INT32      Stream_Time;
extern U_INT32      Gsv1_Time;
extern U_INT32      Gsv2_Time;
extern BIT8         Stuck_Valve;
extern BIT8         New_Stream_No;
extern U_INT8       Been_There;
extern U_INT8       Stream_No;


/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/

void DetermineValvesConfig( void );
void InitializeValves( void );
void SetValveDefaultSetpts (void);
void SetValveDefaultConfig (void);
void ResetMultiposController (void);
void ServiceGsvAndMultiValve (void);
void EvaluateValveReadiness (void);
void RestoreMultiValve (void);
void UpdateGsvStateMachine (ON_OFF state, U_INT8 valve, ON_OFF old_state);

void SwitchMultiValve (ON_OFF state);
void RTTSetValve (ON_OFF state, U_INT8 valve);
void SwitchValveImage (ON_OFF state, U_INT8 valve);
void StartGsvRun (void);
void StartGsvInjRun (void);  /* for workstation Gsv injections */

void CheckValveConfig (void);    /* for workfile check */
void TakeThisValveConfigAndShoveIt (void);
void DefaultGsvInletIfHwChanged (U_INT8 valve);

#endif
